package cn.cmft.jc.transform.parse.strategy;

import cn.cmft.jc.transform.parse.ChangeDetail;
import net.sf.jsqlparser.statement.alter.AlterExpression;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class RenameColumnParser implements AlterExpressionParser {
    @Override
    public List<ChangeDetail> parse(AlterExpression alterExpression) {
        ArrayList<ChangeDetail> changeDetails = new ArrayList<>();

        String columnOldName = alterExpression.getColumnOldName();
        String columnName = alterExpression.getColumnName();
        if (Objects.isNull(columnOldName) || Objects.isNull(columnName)){
            return changeDetails;
        }

        ChangeDetail changeDetail = new ChangeDetail();
        changeDetail.setOldColumnName(columnOldName);
        changeDetail.setCurrentColumnName(columnName);
        changeDetails.add(changeDetail);
        return changeDetails;
    }
}
